home *** CD-ROM | disk | FTP | other *** search
/ MacTech 1 to 12 / MacTech-vol-1-12.toast / Source / MacTech® Magazine / Volume 10 - 1994 / 10.10 Oct 94 / Learning Smalltalk / WireListModel.st < prev    next >
Encoding:
Text File  |  1994-09-13  |  8.5 KB  |  114 lines  |  [TEXT/QKSA]

  1.  
  2. DemoLib
  3.              name: #WireListModel
  4.        superclass: Environment@#ApplicationModule
  5.             flags: 0x0
  6.          category: #'Application Module'
  7. classInstanceVars: nil
  8. namedInstanceVars: #(wires)
  9.     classPoolVars: nil
  10.             pools: nil
  11.        structures: nil
  12.       storageSize: 0
  13. !
  14. (DemoLib@#WireListModel) metaclass description: (Text from: 'This is tutorial application to help people learn SmalltalkAgents™. It is based on an MVC example that appeared in the Tektronix™ versions of Smalltalk. See class method "NOTES" for use description and discussion.' styleRuns:((ScrapStyle basicNew: 0) storageSize: 22; storageFromHexString: '000100000000000C000A000100000009000000000000'))!
  15. (DemoLib@#WireListModel) metaclass  compileMethodSource: (
  16. Text from: 'NOTES
  17.  
  18.     “
  19.     Some notes about this application.......  by R. L. Peskin 7/93
  20.     
  21.     
  22.     The WireListModel is a tutorial application for SmalltalkAgents™. I first encountered this as a tutorial for the MVC paradigm common in earlier versions of Smalltalk, namely in Tektronix™ Smalltalk. The application is a "take off" on the traveling salesman problem. The user selects a set of points via mouse clicks. The objective is to reorder the points so that the total distance between points is a minimum. This problem (with applications to salesmans'' routes and to wire routing on circuit boards) is known to be NP Complete; i.e. there is no deterministic solution computable in polynomial time. The approach taken here is a ''stochastic'' one. We will randomly interchange points until (hopefully) we attain the desired minimum. There are, of course, problems with this approach. There is no way of telling in advance how many random trials are needed to get the minimum. Also, any minmum attained by this method is not guaranteed to be a true minimum; the stochastic system may relax to an intermediate state (i.e. a false minimum), and external preturbations (e.g. moving one of the points will be required) if the system is to proceed towards its true minimum.  
  23.  
  24.     Some caveats
  25.     In order to keep this demo application simple, some "hacks" were done in WireListWindow to avoid adding more components than necessary. See our DESolver demo for a complete window example.
  26.     Our category choices were made to help ease the learning process; they do not conform to the conventions used in other Smalltalk systems.
  27.     The decision to place drawing methods in the WireList class is based on the decision that these are primarily geometric operations using the data, not generic display opeations. Others may disagree.
  28.     Distance between point methods (Euclidean distance) are usually found in class Point. In STA class Point is special, it refers to Macintosh type points. We have begun to develop class co-ordinate, which will include such functions, but we chose not to use this here in order to keep the demo self contained. (See the TurtleGraphics class we will place on the QKS ftp site.) 
  29.     We will also put a class Random, a Stream subclass on the ftp site. Again for this demo we do not use this, but rather generate random numbers using the class Float random method. 
  30.     We chose to reference the WireList as an instance variable of the application (WireListModel), because we feel that the "nerve center" should control access its "models" (computations and data) and its views (windows). Another choice would be to have the WireListWindow acess the WireList directly; this might ease the fileIn problem at the expense of less code clarity.”' styleRuns:((ScrapStyle basicNew: 0) storageSize: 82; storageFromHexString: '000400000000000B000900040100000900000000000000000005000B0009000400000009000000000000000004F7000B000900040400000900000000000000000504000B0009000400000009000000000000'))!
  31. ((DemoLib@#WireListModel) metaclass  methodAt: #'NOTES') protocolCategory: 'identity'.!
  32.  
  33. DemoLib@#WireListModel compileMethodSource: (
  34. Text from: 'add: aPoint
  35.  
  36.     "Adds a point to the end of the WireList"
  37.  
  38.     
  39.     wires add: aPoint' styleRuns:((ScrapStyle basicNew: 0) storageSize: 62; storageFromHexString: '000300000000000B000900040000000900000000000000000011000B00090004000000099999666600000000003A000B0009000400000009000000000000'))!
  40. (DemoLib@#WireListModel methodAt: #'add:') protocolCategory: #'accessing'.!
  41. (DemoLib@#WireListModel methodAt: #'add:') description: ('Adds a point').!
  42.  
  43. DemoLib@#WireListModel compileMethodSource: (
  44. Text from: 'installMenus
  45.  
  46.      "Install the ''about..''menu"
  47.     MenuBar aboutItem: ''About WireList...''.
  48.     
  49.     
  50.     "Tell the superclass to do the minimal (File) menu install"
  51.     super installMenus.
  52.  
  53.     ' styleRuns:((ScrapStyle basicNew: 0) storageSize: 102; storageFromHexString: '000500000000000B000900040000000900000000000000000012000B00090004000000099999666600000000002E000B000900040000000900000000000000000069000B0009000400000009999966660000000000A4000B0009000400000009000000000000'))!
  54. (DemoLib@#WireListModel methodAt: #'installMenus') protocolCategory: #'menus'.!
  55. (DemoLib@#WireListModel methodAt: #'installMenus') description: ('Minimal menu bar install').!
  56.  
  57. DemoLib@#WireListModel compileMethodSource: (
  58. Text from: 'doAbout
  59.  
  60.     Notifier notify: 
  61.         ‘WireList Application ’,NewLine,NewLine,
  62.         ‘by R. Peskin, S. MacsKassy’,NewLine,
  63.         ‘7/93 ’,‘“Rutgers University CAIP Ctr.”
  64.                  A tutorial application for SmalltalkAgents™’.
  65.  
  66.     ' styleRuns:((ScrapStyle basicNew: 0) storageSize: 262; storageFromHexString: '000D00000000000B0009000400000009000000000000000000280010000C00030100000C0000000000000000003C000D000A00030000000A0000000000000000003D000B000900040000000900000000000000000059000C000A0003000000090000000000000000007E000B000900040000000900000000000000000087000C000A0003000000090000000000000000008B000C000A0003020000090000000000000000008C000B00090004000000090000000000000000008F000B000900040000000900006666CCCC00000090000C000A00030300000900006666CCCC000000AC000C000A00030000000900006666CCCC000000EA000B0009000400000009000000000000'))!
  67. (DemoLib@#WireListModel methodAt: #'doAbout') protocolCategory: #'dialogs'.!
  68. (DemoLib@#WireListModel methodAt: #'doAbout') description: ('Every application needs an about....').!
  69.  
  70. DemoLib@#WireListModel compileMethodSource: (
  71. Text from: 'initializeModule
  72.  
  73.    “Place the following menus in our menuList attribute:   
  74.     File”
  75.     menuList :=
  76.     {
  77.         (Menu new: ''File'')
  78.             add: ''Quit'' selector: #doQuit keyEquiv: $Q.
  79.     }.
  80.  
  81.     ' styleRuns:((ScrapStyle basicNew: 0) storageSize: 102; storageFromHexString: '000500000000000B000900040000000900000000000000000015000B0009000400000009999966660000000000520010000C00000000000C99996666000000000056000B000900040000000999996666000000000057000B0009000400000009000000000000'))!
  82. (DemoLib@#WireListModel methodAt: #'initializeModule') protocolCategory: #'menus'.!
  83. (DemoLib@#WireListModel methodAt: #'initializeModule') description: ('Here we do a minimum initialization; only creating a QUIT item in the FIleMenu').!
  84.  
  85. DemoLib@#WireListModel compileMethodSource: (
  86. Text from: 'launch
  87.  
  88.     "Sending the method ''launch'' to the class WireListModel will result in the superclass
  89.     (ApplicationModule>>launch) method being executed. This latter class method will call
  90.     this Instance method. The Window will also have its instance variable, ''module'' asigned
  91.     as a result of this launch"
  92.   
  93.   
  94.     
  95.     "Create the window instance, label it, and open it"
  96.   (WireListWindow new: self) label: ''WireList''; open.
  97.    
  98.    "Set the WireListModel instance variable, wires to a new WireList"
  99.    wires := WireList new.
  100.    
  101.     ' styleRuns:((ScrapStyle basicNew: 0) storageSize: 142; storageFromHexString: '000700000000000B00090004000000090000000000000000000C000B000900040000000999996666000000000137000B000900040000000900000000000000000147000B00090004000000099999666600000000017A000B0009000400000009000000000000000001B8000B0009000400000009999966660000000001FA000B0009000400000009000000000000'))!
  102. (DemoLib@#WireListModel methodAt: #'launch') protocolCategory: #'initialization'.!
  103. (DemoLib@#WireListModel methodAt: #'launch') description: ('Basic launching method called by ApplicationModule>>launch').!
  104.  
  105. DemoLib@#WireListModel compileMethodSource: (
  106. Text from: 'wires
  107.     
  108.     "Typical accessor method to return an instance variable"
  109.     
  110.     ^wires' styleRuns:((ScrapStyle basicNew: 0) storageSize: 62; storageFromHexString: '000300000000000B00090004000000090000000000000000000E000B000900040000000999996666000000000047000B0009000400000009000000000000'))!
  111. (DemoLib@#WireListModel methodAt: #'wires') protocolCategory: 'attribute accessor'.!
  112. (DemoLib@#WireListModel methodAt: #'wires') description: ('Accessor').!
  113.  
  114.